<!--
 * @name: 
 * @Author: 刘大可
 * @Date: 2022-12-28 12:46:04
 * @LastEditors: 刘大可
 * @LastEditTime: 2023-09-05 12:45:08
-->
<template>
  <view class="school-coupon cu-modal bottom-modal" :class="modalName ? 'show' : ''" @tap="hideModal">
    <view class="cu-dialog" @tap.stop="">
      <view class="cu-bar bg-white tit">
        <view class="action text-blue" @tap="hideModal"></view>
        用户协议及隐私保护
        <!-- 金额：{{ price }} -->
        <view class="action" @tap="hideModal">
          <view class="cuIcon-close"></view>
        </view>
      </view>
      <view class="padding content">
        欢迎你使用本小程序，我们非常重视你的隐私和个人信息保护，为了更好地保障你的个人权益，请你在使用前务必充分阅读<text class="xytit"  @click="handleOpenPrivacyContract">{{ xieyi }} </text> 。我们将严格按照你同意的各项条款使用和保护你的个人信息。
        为了更好地提供产品服务，我们申请获取你的微信呢称和头像。
      </view>
      
      <view class="bottom row">
        <view class="btndk exit row">不同意</view>
        <view class="btndk tongyi row">同意
          <button class="agree-btn" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization"></button>

        
        </view>

      </view>

    </view>
  </view>
</template>
<script>
var app = getApp();

export default {
  data() {
    return {
      modalName: false,
      couponList: [],
      dataList: [],
      xieyi:""
    }
  },
  created(options) {
    console.log(app);
    wx.getPrivacySetting({
      success: res => {
        console.log(res) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
        this.xieyi = res.privacyContractName
        this.showPrivacy = res.needAuthorization
        if (res.needAuthorization) {
          this.showModal()

          // 需要弹出隐私协议
          // this.showPrivacy= true
        } else {
          // 用户已经同意过隐私协议，所以不需要再弹出隐私协议，也能调用已声明过的隐私接口
          // wx.getUserProfile()
          // wx.chooseMedia()
          // wx.getClipboardData()
          // wx.startRecord()
        }
      },
      fail: () => { },
      complete: () => { }
    })
    // this.showModal()
  },
  props: {
    bid: {
      type: String,
    },
    price: {
      type: Number,
      default: 0
    }
    // sys: {
    //     type: object,
    // }
  },
  methods: {
    tongyi(){
      this.go("/gc_school/pages/changeSchool/index")
    },

    
    hideModal() {
      this.modalName = false
      try {
        this.$root.calculate()
      } catch (error) {

      }
    },
    showModal() {
      this.modalName = true
   


    },

    handleAgreePrivacyAuthorization(e) {
      console.log(e);
      this.showPrivacy = false
      this.hideModal()
      this.tongyi()
      // 用户同意隐私协议事件回调
      // 用户点击了同意，之后所有已声明过的隐私接口和组件都可以调用了
      // wx.chooseMedia()
      // wx.getClipboardData()
      // wx.startRecord()
    },
    handleOpenPrivacyContract() {
      // 打开隐私协议页面
      wx.openPrivacyContract({
        success: () => { }, // 打开成功
        fail: () => { }, // 打开失败
        complete: () => { }
      })
    },
   
    checkAuth(){
      return new Promise((resolve, reject) => {
         wx.getPrivacySetting({
          success: res => {
            console.log(res) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
            if (res.needAuthorization) {
              return
              // 需要弹出隐私协议
              // this.showPrivacy= true
            } else {
              resolve(res)
              
              // 用户已经同意过隐私协议，所以不需要再弹出隐私协议，也能调用已声明过的隐私接口
              // wx.getUserProfile()
              // wx.chooseMedia()
              // wx.getClipboardData()
              // wx.startRecord()
            }
          },
          fail: () => { },
          complete: () => { }
        })
      })

     

    }



  },
}
</script>
<style lang="scss">
@import "./main.scss";

.cu-dialog {
  height: 70vh;
  overflow-y: auto;

  .tit {
    position: sticky;
    top: 0px;
  }
}</style>